package org.ddd.book.interfaces;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

@Data
@AllArgsConstructor
public class BaseResult<T> {
    private T data;
    private int code;
    private String msg;

    public static <P> BaseResult<P> success(P data) {
        return success(data, null);
    }

    @SuppressWarnings("all")
    public static <P> BaseResult<P> success(P data, String msg) {
        return new BaseResult(data, ResultCode.SUCCESS.getCode(), msg);
    }

    @SuppressWarnings("all")
    public static <P> BaseResult<P> fail(String msg) {
        return new BaseResult(null, ResultCode.FAIL.getCode(), msg);
    }

    @AllArgsConstructor
    @Getter
    enum ResultCode {
        SUCCESS(1), FAIL(-1), NO_PERMISSION(-2);
        private final int code;
    }
}
